package com.mujin.keji.collectionsystem.module.main.viewmodel;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModel;
import android.os.Build;

import com.mujin.keji.collectionsystem.base.BaseDto;
import com.mujin.keji.collectionsystem.module.main.dto.QueryPhoneDto;
import com.mujin.keji.collectionsystem.module.main.dto.SavePhoneDto;
import com.mujin.keji.collectionsystem.module.main.repository.IQueryPhoneRepository;
import com.mujin.keji.collectionsystem.module.main.repository.ISavePhoneRepository;
import com.mujin.keji.collectionsystem.module.main.repository.QueryPhoneRepository;
import com.mujin.keji.collectionsystem.module.main.repository.SavePhoneRepository;
import com.mujin.keji.collectionsystem.module.main.vo.QueryPhoneVo;
import com.mujin.keji.collectionsystem.module.main.vo.SavePhoneVo;
import com.mujin.keji.collectionsystem.module.mypager.dto.LateVersionDto;
import com.mujin.keji.collectionsystem.module.mypager.repository.IVersionLatestRepository;
import com.mujin.keji.collectionsystem.module.mypager.repository.VersionLatestRepository;
import com.mujin.keji.collectionsystem.module.mypager.vo.LateVersionVo;
import com.mujin.keji.collectionsystem.module.outboundtask.vo.QueryUserVo;

/**
 * 首页viewmodel
 *
 * @author weishixiong
 * @Time 2018-05-5
 */
public class MainViewModel extends ViewModel {
    private LiveData<BaseDto<SavePhoneDto>> dtoLiveData;
    private ISavePhoneRepository savePhoneRepository;
    private LiveData<BaseDto<QueryPhoneDto>> queryPhoneLiveData;
    private IQueryPhoneRepository queryPhoneRepository;
    private IVersionLatestRepository latestRepository;
    private LiveData<BaseDto<LateVersionDto>> versionLatestLiveData;

    /**
     * 获取最新版本
     *
     * @param os 操作系统
     * @return
     */
    public LiveData<BaseDto<LateVersionDto>> lasted(Integer os) {
        LateVersionVo vo = new LateVersionVo(os);
        latestRepository = new VersionLatestRepository();
        this.versionLatestLiveData = latestRepository.lasted(vo);
        return versionLatestLiveData;
    }

    /**
     * 保存手机号码
     *
     * @param imei
     * @param phoneNumber
     * @return
     */
    public LiveData<BaseDto<SavePhoneDto>> getDtoLiveData(String deviceId, String imei, String phoneNumber, String captacha) {
        SavePhoneVo vo = new SavePhoneVo();
        vo.setDeviceId(deviceId);//设备ID
        vo.setCaptacha(captacha);//短信验证码
        vo.setPhoneModel(android.os.Build.BRAND);//获取手机型号
        vo.setOsVersion(String.valueOf(Build.VERSION.SDK_INT));// 系统版本
        vo.setImei(imei);//imei
        vo.setPhoneNumber(phoneNumber);//本机号码
        vo.setSource(2);//来源 1IOS 2 安卓
        savePhoneRepository = new SavePhoneRepository();
        this.dtoLiveData = savePhoneRepository.savePhone(vo);
        return dtoLiveData;
    }

    /**
     * 查询手机号码
     *
     * @param imei
     * @return
     */
    public LiveData<BaseDto<QueryPhoneDto>> getDtoLiveData(String imei) {
        QueryPhoneVo vo = new QueryPhoneVo();
        vo.setImei(imei);
        queryPhoneRepository = new QueryPhoneRepository();
        this.queryPhoneLiveData = queryPhoneRepository.queryPhone(vo);
        return queryPhoneLiveData;
    }
}
